// pages/caipan1/caipan1.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    res: null,
    list:[],
    checked: [],
    refreshCard: null,
    refreshChecked: null,
    refresh: null,
    cardModal: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      res: options.resData
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      list:JSON.parse(this.data.res)
    })
    console.log(this.data.list)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    that.data.refreshChecked=setInterval(function(){
      for (var i in that.data.list) {
        that.data.checked[i] = that.data.list[i].checked
      }
      console.log(that.data.checked)
      if(that.data.checked.includes(false)){
        console.log(that.data.checked.includes(false))
        that.data.refreshCard = function () {
          wx.request({
            url: app.globalData.baseUrl + '/refresh_referee_poker',
            method: "post",
            success: function (res) {
                that.setData({
                  plateList: res.data
                })
            }
          })
        }
      }else{
        clearInterval(that.data.refreshCard)
        clearInterval(that.data.refresh)
        clearInterval(that.data.refreshChecked)
      }
    }, 1000)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //下一局
  next: function () {
    // this.Modal.showModal();
    // this.data.cardModal.showModal();
  },
  //返回
  back: function () {
    wx.navigateBack({
      delta: 2
    })
    clearInterval(this.data.refreshCard)
    clearInterval(this.data.refresh)
    clearInterval(this.data.refreshChecked)
  }
})